/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
            佛祖保佑       永无BUG
*/

$NG.AllReady(function (
	page,
	{ useAction, useValuesChange, useUpdateRows, useDataIndexChange, useClick }
) {
	const mstform = $NG.getCmpApi("p_form_employ_task");
	const dgrid1 = $NG.getCmpApi("p_form_employ_task_d");
	useValuesChange(({ args }) => {
		getTaskInfo();
        getUserInfo()
	}, "p_form_employ_task.u_name");

	useUpdateRows(({ args }) => {
		console.log(`表格监听`);
		const _d1arr = dgrid1.getRows();
		let u_self_score = 0;
		let u_reevaluate_score = 0;
		_d1arr.forEach((element) => {
			u_self_score += element.u_self_score ? element.u_self_score : 0;
			u_reevaluate_score += element.u_reevaluate_score
				? element.u_reevaluate_score
				: 0;
		});
		console.log("数组", u_reevaluate_score, u_self_score);
		$NG.updateState((updater) => {
			updater.data.p_form_employ_task.setProps({
				u_self_score: u_self_score,
				u_reevaluate_score: u_reevaluate_score,
			});
		});
	}, "p_form_employ_task_d");
	if(page.oType == 'add'){
        getTaskInfo();
    }
    function getTaskInfo() {
		dgrid1.clearRows();
		$NG.execServer("getTaskInfo", {}, (res) => {
			const _data = JSON.parse(res.data);
			console.log(`获取用工模板`, _data, res);
			const _rowArr = [];
			_data.forEach((element) => {
				_rowArr.push({
					u_type: element.extendObjects.u_category,
					u_score: element.extendObjects.u_score,
				});
			});
			dgrid1.addRows(_rowArr);
		});
	}
	function getUserInfo() {
		$NG.execServer(
			"getWbInfo",
			{ yg: mstform.getItem("u_name").getValue() },
			function (res) {
				console.log(`人员信息获取`, JSON.parse(res.data), res);
				const _data = JSON.parse(res.data)[0].extendObjects;
				$NG.updateState((updater) => {
					updater.data.p_form_employ_task.setProps({
						u_sex: _data.xb == "1" ? "男" : "女",
						phid_pc: {
							label: _data.xm_name,
							value: _data.xm,
						},
						idno: _data.sfz,
						u_employment_position: {
							label: _data.gwmc,
							value: _data.gw,
						},
						u_division: {
							label: _data.syb_name,
							value: _data.syb,
						},
						u_employment_type: _data.yglx,
						u_entry_dt: _data.rzsj,
						u_cnt_end_dt: _data.dqsj,
					});
				});
			}
		);
	}
});
